package api

import (
	goods "api-gateway/basic/goods_proto"
	"api-gateway/basic/inits"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"github.com/gin-gonic/gin"
)

// GoodsWelcomeSearchList
// @Summary      首页搜索列表
// @Description  首页搜索列表
// @Tags         首页模块
// @Accept       json
// @Produce      json
// @Param        goodsWelcomeSearch  query      request.WelcomeSearchList  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Router       /goodsWelcomeSearch/WelcomeSearchList [get]
func GoodsWelcomeSearchList(c *gin.Context) {
	var v request.WelcomeSearchList
	if err := c.ShouldBind(&v); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	allGoods, err := inits.GoodsClient.WelcomeSearchShopList(c, &goods.WelcomeSearchShopListReq{
		BrandName: v.BrandName,
		Page:      v.Page,
		PageSize:  v.PageSize,
	})
	if err != nil {
		response.Error(c, 500, "查询失败", err.Error())
		return
	}
	response.Error(c, 200, "查询成功", allGoods)
}

// GoodsWelcomeSearch
// @Summary      首页搜索
// @Description  首页搜索
// @Tags         首页模块
// @Accept       json
// @Produce      json
// @Param        goodsWelcomeSearch  query      request.WelcomeSearch  true  "首页参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Router       /goodsWelcomeSearch/WelcomeSearch [get]
func GoodsWelcomeSearch(c *gin.Context) {
	var v request.WelcomeSearch
	if err := c.ShouldBind(&v); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	data, err := inits.GoodsClient.WelcomeSearch(c, &goods.WelcomeSearchReq{
		BrandName: v.BrandName,
	})
	if err != nil {
		response.Error(c, 500, "查询失败", err.Error())
		return
	}
	response.Error(c, 200, "查询成功", data)
}
